var urlKYXContent = 'ECI/WeChatSmallProgram/WeChat_Base.ashx?AppKey=049BD15C6FC04BD80808A601DC46E50515CBEEA33FB29AB4'; //kouyuxiu/IES_base.ashx
// var urlKYXContent = 'ECI/kouyuxiu/IES_base.ashx?AppKey=049BD15C6FC04BD80808A601DC46E50515CBEEA33FB29AB4'; 
var urlWJWContent = 'ECI/waijiao/User_Base.ashx?AppKey=049BD15C6FC04BD80808A601DC46E50515CBEEA33FB29AB4';
var urlYTBContent = 'ECI/TOEFL_IEITS/TO_IE_Base.ashx?AppKey=049BD15C6FC04BD80808A601DC46E50515CBEEA33FB29AB4';
var urlXCXContent = 'ECI/xiaochengxu/IES_base.ashx?AppKey=049BD15C6FC04BD80808A601DC46E50515CBEEA33FB29AB4';
const urlShanBContent = 'https://api.shanbay.com/bdc/search/';

var wxRequest = (params, url) => {

    // let P = new Promise(function(resolve, reject) {
    wx.request({
        url,
        method: params.method || 'GET',
        data: params.dataDic || {},
        header: {
            Accept: 'application/json',
            'content-type': params.contentType || 'application/json',
        },
        success(res) {
            if (params.success) {
                params.success(res);
            }
            // resolve(res)
        },
        fail(err) {
            if (params.fail) {
                params.fail(err);
            }
            // reject(err)
        },
        complete(res) {
            console.log('本次网络请求的url:', url)
            console.log('本次网络请求发送的数据:', params.dataDic)
            if (params.complete) {
                params.complete(res);
            }
        },
    });
    // });
    // return P;

};

//获取首页数据
var methodGetWechatIndexPage = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetWechatIndexPage`);
}

//获取随机红包金额
var methodGetRedEnvelopesAmount = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetRedEnvelopesAmount`);
}

//获取每日更新列表
var methodGetDailyUpdatesList = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetDailyUpdatesList`);
}

//获取随机红包金额
var methodReceiveRedEnvelopes = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=ReceiveRedEnvelopes`);
}

//获取账户提现规则列表
var methodGetAccountPresentationRulesList = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetAccountPresentationRulesList`);
}

//用户账户提现
var methodUserAccountWithdrawals = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=UserAccountWithdrawals`);
}

//获取账户交易明细
var methodGetUserAccountDetails = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetUserAccountDetails`);
}

//********************************************************************************************************//


//获取某日排行榜数据
var methodGetDailyChallengeRankingList = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetDailyChallengeRankingList`);
}

//获取奖金排行榜信息
var methodGetMoneyAwardList = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetRewardRankingList`);
}

//增加分享人的练习次数
var methodAddPracticeNumbers = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=AddPracticeNumbers`);
}

//获取练习次数
var methodGetChallengeCount = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetChallengeCount`);
}

//发送formId到后台
var methodSendFormId = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=SendFormId`);
}

//获取小程序二维码
var methodGetWxaCode = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetWxaCode`);
}

// 获取微信openid
var methodRequestWechatAPI = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=RequestWechatAPI`);
};

// 发送用户注册验证码
var methodWechatGetSMSCode = (params) => {
    /*********** 接口统一使用微信小程序虚拟路径 */
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatGetSMSCode`);
    /***********/
};

// 用户注册
var methodWechatRegister = (params) => {
    /*********** 接口统一使用微信小程序虚拟路径 */
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatRegister`);
    /***********/
};

// 获取每日更新和热门推荐
var methodGetDailyUpdatesAndHotRecommendation = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetDailyUpdatesAndHotRecommendation`);
};

// 选择视频进入练习
var methodWechatStartLearning = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatStartLearning`);
};

// 提交录音获取分数 
var methodWechatSumbitMyVoice = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatSumbitMyVoice`);
};

// 获取排行榜数据
var methodGetRankingList = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetRankingList`);
};

// 用户登录
var methodWechatLogin = (params) => {
    /*********** 接口统一使用微信小程序虚拟路径 */
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatLogin`);
    /***********/
};

// 根据日期选择获取练习记录
var methodGetUserLearningRecords = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetUserLearningRecords`);
};

// 点赞他人的练习
var methodWeiXinUserPointPraise = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WeiXinUserPointPraise`);
};

// 获取用户录音文件
var methodGetUserVoice = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetUserVoice`);
};

// 获取accessToken 
var methodGetWechatToken = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetWechatToken`);
};

// 获取视频信息和字幕集合
var methodWechatGetVideoInfo = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatGetVideoInfo`);
};

// 获取用户分数和信息
var methodWechatGetUserScoreAndVideoInfo = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatGetUserScoreAndVideoInfo`);
};

// 用户练习记录
var methodGetUserLearningRecordsNew = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetUserLearningRecordsNew`);
};

// 发送消息模板
var methodSendTemplateMessage = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=SendTemplateMessage`);
};

// 获取二维码
var methodGetWxaCode = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetWxaCode`);
};

/*********** 新增换一换接口 */
// 首页换一换
var methodCategoryChangeOneChange = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=CategoryChangeOneChange`);
};
/***********/

//获取网络图片接口
var methodGetBannerAndActivityRules = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetBannerAndActivityRules`);
};

//获取登录验证码
var methodWechatGetVerificationCode = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatGetVerificationCode`);
}

//短信验证码登录
var methodWechatLoginByVerificationCode = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatLoginByVerificationCode`);
}

//口语pk接口**************************************************************************************************//

//首页初次加载获取练习语句
var methodGetIndexPracticeSentence = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetIndexPracticeSentence`);
    }
    //获取指定练习语句
var methodGetAssignPracticeSentence = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetAssignPracticeSentence`);
    }
    //随机切换练习语句
var methodGetRandomPracticeSentence = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetRandomPracticeSentence`);
    }
    //开始学习接口(未点评测时：先上传用户信息)
var methodWechatDailyVoiceStartLearning = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatDailyVoiceStartLearning`);
    }
    //开始学习接口(点击评测时：上传录音等)
var methodSubmitDailyVoiceInfo = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=SubmitDailyVoiceInfo`);
    }
    //获取排行榜信息
var methodGetDailyVoiceRankListInfo = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetDailyVoiceRankListInfo`);
    }
    //获取每日一句奖励排行列表
var methodGetDailyRewardRankingList = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetDailyRewardRankingList`);
    }
    //根据时间获取当日挑战排行信息
var methodGetDailyChallengeRankingList = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetDailyChallengeRankingList`);
    }
    //添加播放次数
var methodAddPlayNum = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=AddPlayNum`);
    }
    //获取难点词汇
var methodGetDifficultWords = (params) => {
        wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetDifficultWords`);
    }
    //查询单词获取详情
var methodGetWordDetail = (params) => {
    wxRequest(params, `${urlShanBContent}`);
};
//获取口语PK每日一句
var methodWechatGetEveryDayVoice = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=WechatGetEveryDayVoice`);
}

//我的页面签到和pk记录接口**************************************************************************************************//

// 获取用户连续签到的天数 
var methodGetSmallProgramUserContinueSignDays = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetSmallProgramUserContinueSignDays`);
}

//签到领取红包
var methodSignReceiveRedEnvelopes = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=SignReceiveRedEnvelopes`);
}

//根据不同类型分页获取某个用户每日一句所有的练习记录
var methodGetDailySortByDifferentType = (params) => {
    wxRequest(params, `${getApp().globalData.apiUrl}/${urlKYXContent}&action=GetDailySortByDifferentType`);
}

module.exports = {
    //获取首页数据
    methodGetWechatIndexPage,
    //获取随机红包金额
    methodGetRedEnvelopesAmount,
    //获取每日更新列表
    methodGetDailyUpdatesList,
    //获取随机红包金额
    methodReceiveRedEnvelopes,
    //获取账户提现规则列表
    methodGetAccountPresentationRulesList,
    //用户账户提现
    methodUserAccountWithdrawals,
    //获取账户交易明细
    methodGetUserAccountDetails,
    //获取某日排行榜数据
    methodGetDailyChallengeRankingList,
    //获取奖金排行榜信息
    methodGetMoneyAwardList,
    //增加分享人的练习次数
    methodAddPracticeNumbers,
    //获取练习次数
    methodGetChallengeCount,
    //发送formId到后台
    methodSendFormId,
    //获取小程序二维码
    methodGetWxaCode,
    // 获取微信openid
    methodRequestWechatAPI,
    // 发送用户注册验证码
    methodWechatGetSMSCode,
    // 用户注册
    methodWechatRegister,
    // 获取每日更新和热门推荐
    methodGetDailyUpdatesAndHotRecommendation,
    // 选择视频进入练习
    methodWechatStartLearning,
    // 提交录音获取分数 
    methodWechatSumbitMyVoice,
    // 获取排行榜数据
    methodGetRankingList,
    // 用户登录
    methodWechatLogin,
    // 根据日期选择获取练习记录
    methodGetUserLearningRecords,
    // 点赞他人的练习
    methodWeiXinUserPointPraise,
    // 获取用户录音文件
    methodGetUserVoice,
    // 获取accessToken 
    methodGetWechatToken,
    // 获取视频信息和字幕集合
    methodWechatGetVideoInfo,
    // 获取用户分数和信息
    methodWechatGetUserScoreAndVideoInfo,
    // 用户练习记录
    methodGetUserLearningRecordsNew,
    // 发送消息模板
    methodSendTemplateMessage,
    /*********** 新增换一换接口 */
    methodCategoryChangeOneChange,
    /***********/
    methodGetBannerAndActivityRules,
    //新增发送短信验证码接口
    methodWechatGetVerificationCode,
    //新增短信验证验登录
    methodWechatLoginByVerificationCode,
    //首页初次加载获取练习语句
    methodGetIndexPracticeSentence,
    //获取指定练习语句
    methodGetAssignPracticeSentence,
    //随机切换练习语句
    methodGetRandomPracticeSentence,
    //开始学习接口(未点评测时：先上传用户信息)
    methodWechatDailyVoiceStartLearning,
    //开始学习接口(点击评测时：上传录音等)
    methodSubmitDailyVoiceInfo,
    //获取排行榜信息
    methodGetDailyVoiceRankListInfo,
    //获取每日一句奖励排行列表
    methodGetDailyRewardRankingList,
    //根据时间获取当日挑战排行信息
    methodGetDailyChallengeRankingList,
    //添加播放次数
    methodAddPlayNum,
    //获取难点词汇
    methodGetDifficultWords,
    /** 新增单词查询 */
    methodGetWordDetail,
    //获取口语PK每日一句
    methodWechatGetEveryDayVoice,
    //获取用户连续签到的天数
    methodGetSmallProgramUserContinueSignDays,
    //签到领取红包
    methodSignReceiveRedEnvelopes,
    //根据不同类型分页获取某个用户每日一句所有的练习记录
    methodGetDailySortByDifferentType
};